package com.cn.crmsystem.controller.systemController;

import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Notice;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.User;
import com.cn.crmsystem.service.systemService.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "公告管理", tags = "公告增删改查API")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @RequestMapping("/selectNotice")
    @ApiOperation(value = "查询公告接口",notes = "管理员和员工都可查询公告",httpMethod = "POST",response = ResultJson.class)
    public ResultJson selectNotice(@RequestBody @ApiParam(name = "notice", value = "筛选公告名称",required = false) Notice notice){
        System.out.println("----查询所有公告----");
        return noticeService.selectNotice(notice);
    }

    @RequestMapping("/addNotice")
    @ApiOperation(value = "新增公告接口",notes = "管理员新增公告",httpMethod = "POST", response = ResultJson.class)
    public ResultJson addNotice(@RequestBody
                                            @ApiParam(name = "notice",value = "类类型数据",required = false) Notice notice){
        System.out.println("----新增公告----");
        Login login = (Login)SecurityUtils.getSubject().getPrincipal();
        System.out.println("-=-=-=-=-==-=-=="+login);
//        Login login = new Login();
//        login.setUser_id(1);
        System.out.println(login.getUser_id());
        return noticeService.addNotice(notice,login);
    }

    @RequestMapping("/deleteNotice")
    @ApiOperation(value = "删除公告接口", notes = "管理员删除公告",httpMethod = "POST", response = ResultJson.class)
    public ResultJson deleteNotice(@RequestParam @ApiParam(name = "id", value = "当前数据编号id",required = false) Integer id){
        System.out.println("----删除公告----");
        return noticeService.deleteNotice(id);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteManyNotice",method = RequestMethod.POST)
    @ApiOperation(value ="批量删除公告数据接口",notes = "传入要删除的数据id",httpMethod = "post",response = ResultJson.class)
    @ApiImplicitParam(name = "ids",value = "公告id",paramType = "query",dataType = "int",required = false)
    public ResultJson deleteManyNotice(Integer[] ids) {
        System.out.println(ids.length);
        return noticeService.deleteManyNotice(ids);
    }

    @RequestMapping("/updateNotice")
    @ApiOperation(value = "修改公告接口", notes = "管理员修改公告",httpMethod = "POST",response = ResultJson.class)
    public ResultJson updateNotice(@RequestBody
                                       @ApiParam(name = "notice", value = "类类型数据",required = false) Notice notice){
        System.out.println("----修改公告----");
        Login login = (Login)SecurityUtils.getSubject().getPrincipal();
        System.out.println("-=-=-=-=-==-=-=="+login);
//        Login login = new Login();
//        login.setUser_id(1);
        System.out.println(login.getUser_id());
        return noticeService.updateNotice(notice,login);
    }

}
